home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 30.9 KB | 1,094 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UUndo.cp
- // Copyright © 1996 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- #ifndef __UUNDO__
- #include "UUndo.h"
- #endif
-
- // MacApp
-
- #ifndef __UAPPLEEVENTS__
- #include "UAppleEvents.h"
- #endif
-
- #ifndef __UDISPATCHER__
- #include "UDispatcher.h"
- #endif
-
- #ifndef __UFAILURE__
- #include "UFailure.h"
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include "UMacAppGlobals.h"
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include "UMacAppUtilities.h"
- #endif
-
- #ifndef __UMENUMGR__
- #include "UMenuMgr.h"
- #endif
-
- // Toolbox
-
- #ifndef __AEREGISTRY__
- #include <AERegistry.h>
- #endif
-
- // ANSI
-
- #ifndef __STDIO__
- #include <stdio.h>
- #endif
-
- //========================================================================================
- // GLOBAL Variables
- //========================================================================================
-
- TUndoHandler* TUndoHandler::fgUndoHandler;
-
- const ArrayIndex TActionStack::sMaxDesiredItems = 25; // Maximum number of entried in stack.
-
- //========================================================================================
- // GLOBAL Procedures
- //========================================================================================
- #undef Inherited
-
- //----------------------------------------------------------------------------------------
- // GetUndoText:
- //----------------------------------------------------------------------------------------
- #pragma segment MAApplicationRes
-
- void GetUndoRedoText(Boolean cmdDone, CommandNumber aCommandNumber, CStr255& undoName)
- {
- short newMenuState;
-
- if (aCommandNumber == cCantUndo)
- newMenuState = bzCantUndo;
- else if (cmdDone)
- newMenuState = bzUndo;
- else
- newMenuState = bzRedo;
-
- GetIndString(undoName, kIDBuzzString, newMenuState);
-
- short preCmdName;
- short constChars;
- if (ParseTitleTemplate(undoName, preCmdName, constChars))
- {
- CStr255 cmdName;
- if ((aCommandNumber != cNoCommand) && (aCommandNumber != cCantUndo))
- CommandToName(aCommandNumber, cmdName);
- SubstituteInTitle(undoName, cmdName, preCmdName, constChars);
- }
- }
-
- //========================================================================================
- // CLASS TUndoAction
- //========================================================================================
- #undef Inherited
- #define Inherited TObject
-
- #pragma segment MAConstructorRes
- MA_DEFINE_CLASS_M1(TUndoAction, Inherited);
-
- //----------------------------------------------------------------------------------------
- // NewUndoHandler
- //----------------------------------------------------------------------------------------
- #pragma segment MAInit
-
- TUndoAction* TUndoAction::NewUndoAction(TCommand* command, EActionType actionType, CommandNumber id)
- {
- MAVolatileInit(TUndoAction*, it, new TUndoAction);
- FailInfo fi;
- Try(fi)
- {
- it->IUndoAction(command, actionType, id);
- fi.Success();
- }
- else // Recover
- {
- it = (TUndoAction*) FreeIfObject(it);
- fi.ReSignal();
- }
- return it;
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoAction constructor
- //----------------------------------------------------------------------------------------
- #pragma segment MAInit
-
- TUndoAction::TUndoAction() :
- fCommand(NULL),
- fActionType(kSingleAction),
- fMark(FALSE)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoAction destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MATerminate
-
- TUndoAction::~TUndoAction()
- {
- fCommand = (TCommand*) FreeIfObject(fCommand);
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoAction::IUndoAction:
- //----------------------------------------------------------------------------------------
- #pragma segment MAInit
-
- void TUndoAction::IUndoAction(TCommand* command, EActionType actionType, CommandNumber id)
- {
- IObject();
-
- fCommand = command;
- fID = id;
- fActionType = actionType;
- fMark = FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoAction::IsDone:
- //----------------------------------------------------------------------------------------
- #pragma segment MAInit
-
- Boolean TUndoAction::IsDone()
- {
- return fCommand ? fCommand->fCommandDone : FALSE;
- }
-
- //========================================================================================
- // CLASS TActionStack
- //========================================================================================
- #undef Inherited
- #define Inherited TObject
-
- #pragma segment MAConstructorRes
- MA_DEFINE_CLASS_M1(TActionStack, Inherited);
-
- //----------------------------------------------------------------------------------------
- // NewUndoHandler
- //----------------------------------------------------------------------------------------
- #pragma segment MAInit
-
- TActionStack* TActionStack::NewActionStack()
- {
- MAVolatileInit(TActionStack*, it, new TActionStack);
- FailInfo fi;
- Try(fi)
- {
- it->IActionStack();
- fi.Success();
- }
- else // Recover
- {
- it = (TActionStack*) FreeIfObject(it);
- fi.ReSignal();
- }
- return it;
- }
-
- //----------------------------------------------------------------------------------------
- // TActionStack constructor
- //----------------------------------------------------------------------------------------
- #pragma segment MAInit
-
- TActionStack::TActionStack()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TActionStack destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MATerminate
-
- TActionStack::~TActionStack()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TActionStack::IActionStack:
- //----------------------------------------------------------------------------------------
- #pragma segment MAInit
-
- void TActionStack::IActionStack()
- {
- IList();
-
- #if qDebug
- SetEltType(&TUndoAction::fgClassDesc);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // TActionStack::PushAction:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TActionStack::PushAction(TUndoAction* action)
- {
- Push(action);
-
- // Purge some actions if we've busted through the max desired.
- if (fSize > sMaxDesiredItems)
- Purge(kMaxLong, sMaxDesiredItems);
- }
-
- //----------------------------------------------------------------------------------------
- // TActionStack::ClearActionsToMark:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TActionStack::ClearActionsToMark()
- {
- TUndoAction* action;
- while ((action = Top()) != NULL && !action->fMark)
- {
- action = PopAction();
- action = (TUndoAction*) FreeIfObject(action);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TActionStack::FindTransaction:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- TUndoAction* TActionStack::FindTransaction(TCommand* command, Boolean itsForward)
- {
- TUndoAction* transaction = NULL;
- long level = 0;
- Boolean found = FALSE;
-
- CObjectIterator iter(this, itsForward);
- for (TUndoAction* action = (TUndoAction*) iter.FirstObject(); iter.More(); action = (TUndoAction*) iter.NextObject())
- {
- EActionType actionType = action->fActionType;
- if (level == 0)
- {
- if ((actionType == kSingleAction) || (actionType == kBeginAction))
- transaction = action;
- }
-
- if (actionType == kBeginAction)
- ++level;
- else if (actionType == kEndAction)
- --level;
-
- if (action->fCommand == command)
- {
- found = TRUE;
- break;
- }
- }
-
- return found ? transaction : NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // TActionStack::Purge:
- //----------------------------------------------------------------------------------------
- #pragma segment MAMemoryRes
- Size TActionStack::Purge(Size needed, ArrayIndex numToLeave)
- {
- // NOTE: This function does not currently support the 'needed' parameter.
- // Unload possibly even the topmost entry in the stack.
- Size freed = 0;
-
- // Locate the topmost action to which we will unload.
- ArrayIndex i = 0;
- ArrayIndex j = 0;
- ArrayIndex limit = fSize - numToLeave;
-
- while (i <= limit && freed < needed)
- {
- i++;
- TUndoAction* action = (TUndoAction*)At(i);
- Size freeableSize = 0; // Was: action->Size();
-
- EActionType actionType = action->fActionType;
- if (actionType == kBeginAction)
- {
- // Skip over this transaction.
- long transaction = 1;
- do
- {
- i++;
- action = (TUndoAction*)At(i);
- //freeableSize += action->Size();
-
- actionType = action->fActionType;
- if (actionType == kBeginAction)
- ++transaction;
- else if (actionType == kEndAction)
- --transaction;
- } while (i <= limit && transaction != 0);
- }
- if (i <= limit)
- {
- j = i;
- freed += freeableSize;
- }
- }
-
- for (i = 1; i <= j; i++)
- {
- TUndoAction* action = (TUndoAction*)At(i);
- FreeIfObject(action);
- }
-
- // Now flush the targetted entries from the list.
- DeleteElementsAt(1, j);
-
- return freed;
- }
-
- //========================================================================================
- // CLASS TUndoHandler
- //========================================================================================
- #undef Inherited
- #define Inherited TObject
-
- #pragma segment MAConstructorRes
- MA_DEFINE_CLASS_M1(TUndoHandler, Inherited);
-
- //----------------------------------------------------------------------------------------
- // InitUUndoHandler
- //----------------------------------------------------------------------------------------
- #pragma segment MAInit
-
- void TUndoHandler::InitUUndo()
- {
- fgUndoHandler = NewUndoHandler();
- }
-
- //----------------------------------------------------------------------------------------
- // NewUndoHandler
- //----------------------------------------------------------------------------------------
- #pragma segment MAInit
-
- TUndoHandler* TUndoHandler::NewUndoHandler()
- {
- MAVolatileInit(TUndoHandler*, it, new TUndoHandler);
- FailInfo fi;
- Try(fi)
- {
- it->IUndoHandler();
- fi.Success();
- }
- else // Recover
- {
- it = (TUndoHandler*) FreeIfObject(it);
- fi.ReSignal();
- }
- return it;
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoHandler constructor
- //----------------------------------------------------------------------------------------
- #pragma segment MAInit
-
- TUndoHandler::TUndoHandler() :
- fUndoStack(NULL),
- fRedoStack(NULL),
- fInTransaction(0)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoHandler destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MATerminate
-
- TUndoHandler::~TUndoHandler()
- {
- fUndoStack = (TActionStack*) FreeListIfObject(fUndoStack);
- fRedoStack = (TActionStack*) FreeListIfObject(fRedoStack);
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoHandler::IUndoHandler:
- //----------------------------------------------------------------------------------------
- #pragma segment MAInit
-
- void TUndoHandler::IUndoHandler()
- {
- IObject();
-
- fUndoStack = TActionStack::NewActionStack();
- fRedoStack = TActionStack::NewActionStack();
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoHandler::AddActionToHistory:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TUndoHandler::AddActionToHistory(TCommand* command, EActionType actionType, CommandNumber id)
- {
- Boolean shortCut = FALSE;
- if ((fInTransaction > 0) && (actionType == kSingleAction))
- {
- TUndoAction* action = fUndoStack->Top();
- if (action && (action->fActionType == kBeginAction) && (action->fCommand == NULL))
- {
- // Stuff the command in the begin action, instead of allocating
- // a new single action
- action->fCommand = command;
- action->fID = id;
- shortCut = TRUE;
- }
- }
-
- if (!shortCut)
- {
- if (actionType == kBeginAction)
- ++fInTransaction;
- else if (actionType == kEndAction)
- --fInTransaction;
-
- fUndoStack->PushAction(TUndoAction::NewUndoAction(command, actionType, id));
- }
-
- ClearRedoHistory();
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoHandler::BeginAction:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TUndoHandler::BeginAction()
- {
- AddActionToHistory(NULL, kBeginAction, cNoCommand);
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoHandler::EndAction:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TUndoHandler::EndAction()
- {
- Boolean shortCut = TRUE;
- CommandNumber id = cNoCommand;
- TUndoAction* action = fUndoStack->Top();
- if (action)
- {
- if (action->fActionType == kBeginAction)
- {
- if (action->fCommand == NULL)
- {
- // Transaction is empty -- remove it
- fUndoStack->PopAction();
- }
- else
- {
- // Convert to a single action and we don't have to add an end
- action->fActionType = kSingleAction;
- }
- }
- else if ((action->fActionType == kSingleAction))
- {
- // Convert last single action to an end instead of adding one
- action->fActionType = kEndAction;
- }
- else
- {
- // Get the id of the last single action, so the end action
- // will have the same id (for the undo and redo menus)
- id = action->fID;
- shortCut = FALSE;
- }
- }
-
- if (shortCut)
- --fInTransaction;
- else
- AddActionToHistory(NULL, kEndAction, id);
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoHandler::AbortCurrentTransaction:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TUndoHandler::AbortCurrentTransaction()
- {
- if (fInTransaction > 0)
- {
- long nextTransaction = fInTransaction - 1;
- TUndoAction* action;
- while ((action = fUndoStack->PopAction()) != NULL)
- {
- EActionType actionType = action->fActionType;
- action = (TUndoAction*) FreeIfObject(action);
-
- if (actionType == kEndAction)
- ++fInTransaction;
- else if (actionType == kBeginAction)
- {
- if (--fInTransaction <= nextTransaction)
- break;
- }
- }
-
- #if qDebug
- Assertion(fInTransaction == nextTransaction,
- "\pEnd of undo stack before end of transaction");
- #endif
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoHandler::ClearActionHistory:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TUndoHandler::ClearActionHistory(ERespectMarksChoices respectMarks)
- {
- if (respectMarks == kDontRespectMarks)
- {
- fUndoStack->FreeAll();
- fRedoStack->FreeAll();
- }
- else
- {
- fUndoStack->ClearActionsToMark();
- fRedoStack->ClearActionsToMark();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoHandler::MarkActionHistory:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TUndoHandler::MarkActionHistory()
- {
- TUndoAction* action = fUndoStack->Top();
- if (action)
- action->fMark = TRUE;
-
- action = fRedoStack->Top();
- if (action)
- action->fMark = TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoHandler::FindTransaction:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- TUndoAction* TUndoHandler::FindTransaction(TCommand* command)
- {
- TUndoAction* action = fUndoStack->FindTransaction(command, kIterateForward);
- if (!action)
- action = fRedoStack->FindTransaction(command, kIterateBackward);
-
- return action;
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoHandler::Abort:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TUndoHandler::Abort()
- {
- long transaction = fInTransaction;
- // start with fInTransaction so we can abort a partial transaction
-
- do
- {
- EActionType actionType = AbortAction();
- if (actionType == kEndAction)
- ++transaction;
- else if (actionType == kBeginAction)
- {
- --transaction;
- #if qDebug
- Assertion(transaction >= 0, "Bad undo stack");
- #endif
- }
- }
- while (transaction != 0);
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoHandler::Purge:
- //----------------------------------------------------------------------------------------
- #pragma segment MAMemoryRes
- Size TUndoHandler::Purge(Size needed)
- {
- // Unload as much of the undo and redo stack as needed.
- Size totalPurged = fUndoStack->PurgeFirstPhase(kMaxLong);
- if (totalPurged < needed)
- {
- totalPurged = fRedoStack->PurgeFirstPhase(kMaxLong);
- if (totalPurged < needed)
- {
- totalPurged = fUndoStack->Purge(kMaxLong);
- if (totalPurged < needed)
- totalPurged = fRedoStack->Purge(kMaxLong);
- }
- }
- return totalPurged;
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoHandler::Undo:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TUndoHandler::Undo()
- {
- #if qDebug
- Assertion(fInTransaction == 0, "Undo during transaction");
- #endif
- long transaction = 0;
- do
- {
- EActionType actionType = UndoAction();
- if (actionType == kEndAction)
- ++transaction;
- else if (actionType == kBeginAction)
- {
- --transaction;
- #if qDebug
- Assertion(transaction >= 0, "Bad undo stack");
- #endif
- }
- }
- while (transaction != 0);
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoHandler::AnythingToUndo:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- Boolean TUndoHandler::AnythingToUndo()
- {
- return (fUndoStack->fSize > 0);
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoHandler::GetUndoID:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- CommandNumber TUndoHandler::GetUndoID()
- {
- TUndoAction* action = fUndoStack->Top();
- return action ? action->fID : cNoCommand;
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoHandler::GetUndoText:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TUndoHandler::GetUndoText(CStr255& undoName)
- {
- TUndoAction* action = fUndoStack->Top();
- CommandNumber id = action ? action->fID : cNoCommand;
- GetUndoRedoText(kShowUndo, id, undoName);
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoHandler::Redo:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TUndoHandler::Redo()
- {
- #if qDebug
- Assertion(fInTransaction == 0, "Redo during transaction");
- #endif
- long transaction = 0;
- do
- {
- EActionType actionType = RedoAction();
- if (actionType == kBeginAction)
- ++transaction;
- else if (actionType == kEndAction)
- {
- --transaction;
- #if qDebug
- Assertion(transaction >= 0, "Bad redo stack");
- #endif
- }
- }
- while (transaction != 0);
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoHandler::ClearRedoHistory:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TUndoHandler::ClearRedoHistory()
- {
- fRedoStack->FreeAll();
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoHandler::AnythingToRedo:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- Boolean TUndoHandler::AnythingToRedo()
- {
- return (fRedoStack->fSize > 0);
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoHandler::GetRedoID:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- CommandNumber TUndoHandler::GetRedoID()
- {
- TUndoAction* action = fRedoStack->Top();
- return action ? action->fID : cNoCommand;
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoHandler::GetRedoText:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TUndoHandler::GetRedoText(CStr255& undoName)
- {
- TUndoAction* action = fRedoStack->Top();
- CommandNumber id = action ? action->fID : cNoCommand;
- GetUndoRedoText(kShowRedo, id, undoName);
- }
-
- //----------------------------------------------------------------------------------------
- // For internal use only
- //----------------------------------------------------------------------------------------
-
- //----------------------------------------------------------------------------------------
- // TUndoHandler::AbortAction:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- EActionType TUndoHandler::AbortAction()
- {
- TUndoAction* action = fUndoStack->PopAction();
- FailNonObject(action);
-
- EActionType actionType = action->fActionType;
-
- TCommand* command = action->fCommand;
- if (command && command->fCommandDone && command->CanBeUndone() &&
- (command->fValidationError == noErr))
- AbortCommand(command);
-
- return actionType;
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoHandler::AbortCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TUndoHandler::AbortCommand(TCommand* command)
- {
- FailInfo fi;
- Try(fi)
- {
- command->Abort();
- //command->FinishUndoRedo();
- fi.Success();
- }
- else // Recover
- {
- command->SetValidationError(fi.error);
- short aCommandNumber = (short)command->fIdentifier;
- //command = CommitACommand(command);
-
- FailNewMessage(fi.error, fi.message, BuildMessage(aCommandNumber, messageCommandError));
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoHandler::UndoAction:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- EActionType TUndoHandler::UndoAction()
- {
- TUndoAction* action = fUndoStack->Top();
- FailNonObject(action);
-
- EActionType actionType = action->fActionType;
-
- TCommand* command = action->fCommand;
- if (command && command->fCommandDone && command->CanBeUndone() &&
- (command->fValidationError == noErr))
- UndoCommand(command);
-
- fRedoStack->PushAction(fUndoStack->PopAction());
-
- return actionType;
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoHandler::UndoCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TUndoHandler::UndoCommand(TCommand* command)
- {
- FailInfo fi;
- Try(fi)
- {
- command->PrepareForUndoRedo();
- command->UndoIt();
- command->FinishUndoRedo();
- command->RevealUndoRedo();
- fi.Success();
- }
- else // Recover
- {
- command->SetValidationError(fi.error);
- short aCommandNumber = (short)command->fIdentifier;
- //command = CommitACommand(command);
-
- FailNewMessage(fi.error, fi.message, BuildMessage(aCommandNumber, messageCommandError));
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoHandler::RedoAction:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- EActionType TUndoHandler::RedoAction()
- {
- TUndoAction* action = fRedoStack->Top();
- FailNonObject(action);
-
- EActionType actionType = action->fActionType;
-
- TCommand* command = action->fCommand;
- if (command && !command->fCommandDone && command->CanBeUndone() &&
- (command->fValidationError == noErr))
- RedoCommand(command);
-
- fUndoStack->PushAction(fRedoStack->PopAction());
-
- return actionType;
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoHandler::RedoCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TUndoHandler::RedoCommand(TCommand* command)
- {
- FailInfo fi;
- Try(fi)
- {
- command->PrepareForUndoRedo();
- command->RedoIt();
- command->FinishUndoRedo();
- command->RevealUndoRedo();
- fi.Success();
- }
- else // Recover
- {
- command->SetValidationError(fi.error);
- short aCommandNumber = (short)command->fIdentifier;
- //command = CommitACommand(command);
-
- FailNewMessage(fi.error, fi.message, BuildMessage(aCommandNumber, messageCommandError));
- }
- }
-
- //========================================================================================
- // CLASS TUndoRedoCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TCommand
-
- #pragma segment ClassDescRes
- MA_DEFINE_CLASS_M1(TUndoRedoCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TUndoRedoCommand::TUndoRedoCommand: Empty constructor to satisfy the compiler.
- //----------------------------------------------------------------------------------------
- #pragma segment MAApplicationRes
-
- TUndoRedoCommand::TUndoRedoCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoRedoCommand destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TUndoRedoCommand::~TUndoRedoCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoRedoCommand::IUndoRedoCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MAInit
-
- void TUndoRedoCommand::IUndoRedoCommand(CommandNumber itsCommandNumber)
- {
- this->ICommand(itsCommandNumber, gDispatcher, kCantUndo, kDoesNotCauseChange, NULL);
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoRedoCommand::MakeAppleEvent:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScriptingRes
-
- TAppleEvent* TUndoRedoCommand::MakeAppleEvent()
- {
- TAppleEvent* theEvent = new TAppleEvent;
- theEvent->IAppleEvent(kAEMiscStandards, fAEEventID, gServerAddress, kAEWaitReply);
- CTempDesc targetDesc;
- gDispatcher->MakeObjectSpecifier(targetDesc, gDispatcher->GetSpecifierForm());
- theEvent->WriteParameter(keyDirectObject, targetDesc);
- return theEvent;
- }
-
-
- //========================================================================================
- // CLASS TUndoCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TUndoRedoCommand
-
- #pragma segment ClassDescRes
- MA_DEFINE_CLASS_M1(TUndoCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TUndoCommand::TUndoCommand: Empty constructor to satisfy the compiler.
- //----------------------------------------------------------------------------------------
- #pragma segment MAApplicationRes
-
- TUndoCommand::TUndoCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoCommand destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TUndoCommand::~TUndoCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoCommand::IUndoCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MAInit
-
- void TUndoCommand::IUndoCommand(CommandNumber itsCommandNumber)
- {
- this->IUndoRedoCommand(itsCommandNumber);
- fAEEventID = kAEUndo;
- }
-
- //----------------------------------------------------------------------------------------
- // TUndoCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment MAApplicationRes
-
- void TUndoCommand::DoIt()
- {
- TUndoHandler::fgUndoHandler->Undo();
- }
-
- //========================================================================================
- // CLASS TRedoCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TUndoRedoCommand
-
- #pragma segment ClassDescRes
- MA_DEFINE_CLASS_M1(TRedoCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TRedoCommand::TRedoCommand: Empty constructor to satisfy the compiler.
- //----------------------------------------------------------------------------------------
- #pragma segment MAApplicationRes
-
- TRedoCommand::TRedoCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TRedoCommand destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TRedoCommand::~TRedoCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TRedoCommand::IRedoCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MAInit
-
- void TRedoCommand::IRedoCommand(CommandNumber itsCommandNumber)
- {
- this->IUndoRedoCommand(itsCommandNumber);
- fAEEventID = kAERedo;
- }
-
- //----------------------------------------------------------------------------------------
- // TRedoCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment MAApplicationRes
-
- void TRedoCommand::DoIt()
- {
- TUndoHandler::fgUndoHandler->Redo();
- }
-
-
- //========================================================================================
- // CLASS CUndoStackHook
- //========================================================================================
- #undef Inherited
-
- //----------------------------------------------------------------------------------------
- // CUndoStackHook::Purge:
- //----------------------------------------------------------------------------------------
- #pragma segment MAMemoryRes
-
- Size CUndoStackHook::Purge(Size needed)
- {
- // Make memory available by unloading the undo stack. Returns
- // the actual amount of memory purged.
-
- return TUndoHandler::fgUndoHandler->Purge(needed);
- }
-
- //----------------------------------------------------------------------------------------
- // End of UUndo.cp
-
- #pragma segment Inline
-